<#import "../tpl/pageTep.ftl" as page>
    <@page.pageBase currentMenu="返利明细">
    <style>
        .form-horizontal .controls {
            line-height: 40px;
            height: 40px;
            margin-left: 3px;
        }
        .button-primary {
            margin-left: -10px;
        }
        .button-danger{
            margin-left: -25px;
        }
    </style>
    <!--suppress ALL -->
    <form id="searchForm" class="form-panel">
        <ul class="panel-content">
            <li>
                <div class="control-group span5">
                    <div class="search-controls  controls">
                        <input type="text" name="orderPerson" id="title" value="" placeholder="搜索下单人、订单号">
                    </div>
                </div>
                <div class="form-actions span2">
                    <button type="submit" class="button  button-primary">
                        搜索
                    </button>
                </div>
                <div class="form-actions span2" style="width:320px;">
                    <p style="font-size: 13px;"><b>返利分配比例：</b>
                        商品利润的
                        <input id="num" value="" style="width:15px;border: none;" disabled/>
                        %作为返利，返利给上级
                    </p>
                </div>
                <div class="form-actions span2">
                    <a class="button button-success" href="javascript:editFunction()">设置</a>
                </div>
            </li>
        </ul>
    </form>
    <#-------------------------设置弹出框------------------------------>
    <div id="editContent" style="display:none;">
        <form id="editForm" class="form-horizontal" action="${basepath}/rest/manage/brokerage/editPercent" method="post">
            <input type="hidden" class="input-normal control-text" name="id" value="1"/>

            <div class="row">
                <div class="control-group span16">
                    <label class="control-label">金额占利润比例：</label>

                    <div class="controls">
                        <input type="text" id="num1" class="input-normal control-text" name="percent"
                               data-rules="{required : true}"
                               onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                               onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"/>%
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="grid"></div>
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title : '序号',dataIndex :'id', elCls: 'center', width:'15%'},
                {title : '下单人',dataIndex :'orderPerson', elCls: 'center',width:'15%'},
                {title : '下单日期',dataIndex :'createTime', elCls: 'center',width:'20%'},
                {title : '订单号',dataIndex :'orderID', elCls: 'center',width:'20%'},
                {title : '获利方',dataIndex :'profitPerson', elCls: 'center',width:'15%'},
                {title : '获得返利金额（元）',dataIndex :'money', elCls: 'center',width:'15%',renderer:function(data,value){
                    return '<p>'+data+'</p>';
                }}
            ];

    var store = new Store({
                url : 'loadData',
                autoLoad:true, //自动加载数据
                params : { //配置初始请求的参数
                    length : '10'
                },
                pageSize:10,	// 配置分页数目
                root : 'list',
                totalProperty : 'total'
            }),
            grid = new Grid.Grid({
                render:'#grid',
                columns : columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar:{
                    pagingBar:true
                }
            });
    grid.render();
    //搜索框表单
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;//不用form表单提交
    });
    /*------------------设置弹出框----------------------------*/
    var editForm = new BUI.Form.HForm({
        srcNode: '#editForm',
        submitType: 'ajax',
        callback: function (data) {
            if(data.success==false){
                BUI.Message.Alert("返利占比需小于100%！");
            }else {
                var obj = new Object();
                obj.start = 0; //返回第一页
                store.load(obj);
                queryPercent();
                editDialog.close();
            }
        }
    });
    editForm.render();
    var editDialog = new BUI.Overlay.Dialog({
        title: '返利设置',
        width: 350,
        height: 150,
        contentId: 'editContent',
        success: function () {
            if($("#num1").val().length>=3){
                BUI.Message.Alert('返利占比需小于100%!','error');
            }else {
                editForm.submit();
            }
        }
    });
    //编辑按钮事件
    function editFunction() {
        //让返利比例在设置弹出框显示
        $("#num1").val($("#num").val());
        editForm.clearErrors();
        editDialog.show();
    }
    function queryPercent(){
        $.ajax({
            type: "POST",
            url: "${basepath}/rest/manage/brokerage/selectPercent",
            dataType: "json",
            success:function(data){
                $("#num").val(data.data.percent*100);
            }
        })
    }
    queryPercent();
</script>

</@page.pageBase>
